import os
import sys
import json

config_file = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'config.json')

if __name__ == '__main__':
    try:
        with open(config_file, 'r', encoding='utf8') as fp:
            config = json.load(fp)
    except json.decoder.JSONDecodeError:
        print('配置文件读取错误！')
        sys.exit()
    cookies = {}
    source_cookies = input('请输入 Cookie:')
    source_cookies = source_cookies.replace('Cookie:', '').replace(' ', '')
    for item in source_cookies.split(';'):
        temp = item.split('=')
        cookies[temp[0]] = temp[1]
    config['cookies'] = config['webvpn_cookies'] = cookies
    with open(config_file, 'w', encoding='utf8') as fp:
        json.dump(config, fp, indent=4, ensure_ascii=False)
